/**
 * 
 */
package constraints;

import java.util.ArrayList;

import evolution.Gene;

/**
 * @author vtkhanh
 * 
 */
public class HardConstraint {

    public static final short RESOURCE_LIMIT = 60;
    public static final int RESOURCE_LIMIT_COST = 200;
    public static final int DUPLICATE_COST = 200;

    public static boolean isOverResourceLimit(ArrayList<Gene> genes, int timeslot, 
	    int requiredResource) {
	if (requiredResource > RESOURCE_LIMIT) {
	    for (Gene gene : genes) {
		if (gene.getTimeslot() == timeslot) {
		    gene.addCost(RESOURCE_LIMIT_COST);
		    gene.setCostType("OVER_RESOURCE");
		}
	    }
	    return true;
	}
	return false;
    }    

    public static boolean isDuplicate(ArrayList<Gene> genes, Gene gene) {
	int timeslot = gene.getTimeslot();
	gene.getCourse().fillTimeslot(timeslot);
	for (Gene g : genes) {
	    if ((g != gene) && (!g.getCourse().isFreeAtTimeslot(g.getTimeslot()))) {
		gene.getCourse().freeTimeslot(timeslot);
		gene.addCost(DUPLICATE_COST);
		gene.setCostType("DUPLICATE vs G" + g.getGeneId());
		gene.getCourse().freeTimeslot(timeslot);
		return true;
	    }
	}
	gene.getCourse().freeTimeslot(timeslot);
	return false;
    }
}
